package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.exception.LogicException;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 补货工单完成,修改售货机轨道状态,
 */
@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC)

public class SupplyMsgHandler implements MsgHandler {


    @Autowired
    private VendingMachineService vendingMachineService;



    @Override
    public void process(String msg) throws IOException {
        //参数效验
        if (StringUtils.isBlank(msg) || msg == "") {

            throw new LogicException("工单协议参数错误");
        }
        SupplyContract supplyContract = JsonUtil.getByJson(msg, SupplyContract.class);

        //更新售货机库存
        vendingMachineService.supply(supplyContract);



    }
}
